module ew {
    export class Vector2 {
        public x: number;
        public y: number;

        public static zero = new Vector2(0, 0);
        public static unitX = new Vector2(1, 0);
        public static unitY = new Vector2(0, 1);
        public static unit = new Vector2(1, 1);

        constructor(x: number, y: number) {
            this.x = x ? x : 0;
            this.y = y ? y : 0;
        }

        //Non statics

        public getLengthSquared(): number {
            return this.x * this.x + this.y * this.y;
        }

        public getLength(): number {
            return Math.sqrt(this.getLengthSquared());
        }

        public negate(): Vector2 {
            var negated = new Vector2(-this.x, -this.y);
            return negated;
        }

        public add(vector: Vector2): Vector2 {
            var sum = new Vector2(this.x + vector.x, this.y + vector.y);
            return sum;
        }

        public substract(vector: Vector2): Vector2 {
            var difference = new Vector2(this.x - vector.x, this.y - vector.y);
            return difference;
        }

        public multiply(scalar: number): Vector2 {
            var product = new Vector2(this.x * scalar, this.y * scalar);
            return product;
        }
        
        public divide(scalar: number): Vector2 {
            var quotient = new Vector2(this.x / scalar, this.y / scalar);
            return quotient;
        }

        public normalize(): Vector2 {
            var length = this.getLength();
            var normalized = new Vector2(this.x / length, this.y / length);
            return normalized;
        }

        public distanceTo(vector: Vector2): number {
            return this.substract(vector).getLength();
        }
        
        public distanceSquaredTo(vector: Vector2): number {
            return this.substract(vector).getLengthSquared();
        }

        public dot(vector: Vector2): number {
            var product = this.x * vector.x + this.y * vector.y;
            return product;
        }

        public static lerp(vector1: Vector2, vector2: Vector2, amount: number): Vector2 {
            var lerped = new Vector2(vector1.x, vector1.y);
            lerped.x += (vector2.x - vector1.x) * amount;
            lerped.y += (vector2.y - vector1.y) * amount;
            return lerped;
        }
    }
}